package com.company.project.common.utils;

import com.company.project.vo.KeyValueVo;
import com.deepoove.poi.XWPFTemplate;

import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class WordUtils {
    public static void createWord(String templatFile, String descFile, List<KeyValueVo> keyValueVos){
        XWPFTemplate template = XWPFTemplate.compile(templatFile);
        HashMap<String,Object> map = new HashMap<>();
        for (KeyValueVo keyValueVo : keyValueVos) {
            map.put(keyValueVo.getKey(),keyValueVo.getValue());
        }

        template.render(map);
        try {
            template.writeAndClose(new FileOutputStream(descFile) );
        } catch (IOException e) {
            e.printStackTrace();
        }

    }


    public static void main(String[] args) {
        String templatFile = "C:\\mycode\\hkx-manager\\src\\main\\resources\\word_template\\中期检查_模板.docx";
        String descFile = "D:\\hkx中期检查_模板.docx";
        List<KeyValueVo> keyValueVos = new ArrayList<>();
        keyValueVos.add(new KeyValueVo().setKey("p3").setValue("黄可想"));
        WordUtils.createWord(templatFile,descFile,keyValueVos);
    }

}
